import { Config } from "./typechecker";

export function formColumns(item: Config["config"][0]) {
	return {
		name: item.label,
		title: item.label,
		align: "center",
		sortable: item.sort,
	};
}

export interface ISearchMode {
	name: string;
	mode:
		| string
		| {
				key: string;
				val: string;
				weight: number;
		  }[]
		| null;
	val: string;
	isText: boolean;
	isSelect: boolean;
	equal: boolean;
}

export function formModes(item: Config["config"]): ISearchMode[] {
	return item.map((val) => ({
		name: val.label,
		mode: val.mode as {
			key: string;
			val: string;
			weight: number;
		}[],
		val: "",
		isText: typeof val.mode === "string",
		isSelect: Array.isArray(val.mode),
		equal: val.mode === "[=]" || Array.isArray(val.mode),
	}));
}
